/*全国商品类型*/
function RecStyle() {
    $.ajax({
        url: "findRecStyleByRecStyleData",
        type: "POST",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            if (data.code == 500) {
                Swal.fire("提示", "请联系管理人员!", "warning");
            } else {
                var str = null;
                for (var i = 0; i < data.recStyle_List.length; i++) {
                    str += "<option value='" + data.recStyle_List[i].recStyID + "'>" + data.recStyle_List[i].recStyName + "</option>";
                }
            }
            $("#recStyID").append(str);
        }
    });
}

//注册回收品类型信息
function add_Data() {
    var formData = new FormData($("#recProductAddForm")[0]);
    var recProductName = $("#recProductName").val();
    var recProductPrice = $("#recProductPrice").val();
    var recProductUnit = $("#recProductUnit").val();
    var recProductDetail = $("#recProductDetail").val();
    var recStyID = $("#recStyID").val();
    formData.append("recProductName_1", recProductName);
    formData.append("recProductPrice_1", recProductPrice);
    formData.append("recProductUnit_1", recProductUnit);
    formData.append("recProductDetail_1", recProductDetail);
    formData.append("recStyID_1", recStyID);

    $.ajax({
        url: "insertRecycleProductByRecycleProductData",
        type: 'POST',
        data: formData,
        cache: false,
        async: false,
        processData: false,  //必须false才会避开jQuery对 formdata 的默认处理
        contentType: false,  //必须false才会自动加上正确的Content-Type
        success: function (data) {
            if (data.code == 200) {
                Swal.fire("提示", "数据登记成功!", "success");
                $.getJSON("hcontroller/addmiddletable", {uid: uid, hid: hid}, function (json) {
                    console.log(json);
                });
            } else if (data.code == 300) {
                Swal.fire("提示", "请提交相应材料!", "warning");
            } else {
                Swal.fire("提示", "登记数据有误!", "error");
            }
        },
        error: function (data) {
            if (data.code == 500) {
                Swal.fire("提示", "数据提交失败!", "error");
            }
        }
    });

    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index); //执行关闭
    parent.location.href = "/yihuan/Background-RecProductList.html";//回到父级页面
}

//查询回收品类型信息

$("#add_Data").click(function () {
    add_Data();
});


$(function () {
    setTimeout("RecStyle()", 100);
});